/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.storage.api;

import com.jeesite.modules.storage.common.ServerResponse;
import com.jeesite.modules.storage.service.TradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 交易Controller
 */
@RestController(value = "apitrade")
@RequestMapping(value = "/api/trade")
public class TradeController extends APIController {

    @Autowired
    private TradeService tradeService;

    /**
     * 交易汇总
     * @param memberId 会员Id
     * @param monthDate 月份
     * @return 交易汇总
     */
    @RequestMapping(method = RequestMethod.GET,value = "statistics")
    @ResponseBody
    public ServerResponse<Double> statistics(@RequestParam(value="memberId") String memberId,@RequestParam(value="monthDate") String monthDate){
        return ServerResponse.createBySuccess(200,tradeService.getStatisticsByMemberId(memberId,monthDate));
    }

    /**
     * 查询会员交易列表
     * @param memberId 会员Id
     * @param monthDate 月份
     * @param size 每页数量
     * @param page 页码
     * @return 会员交易列表
     */
    @RequestMapping(method = RequestMethod.GET,value = "query")
    @ResponseBody
    public ServerResponse<List<Map>> query(@RequestParam(value="memberId") String memberId,@RequestParam(value="monthDate") String monthDate, @RequestParam(value="size",defaultValue = "5") Integer size, @RequestParam(value="page",defaultValue = "1") Integer page)
    {
        return  ServerResponse.createBySuccess(200,tradeService.getListByMemberId(memberId,monthDate,size,page));
    }

    /**
     * 保存
     * @param memberId 会员Id
     * @param bankId 银行卡Id
     * @param amount 交易金额
     * @return 结果
     */
    @RequestMapping(method = RequestMethod.POST,value = "save")
    public ServerResponse<String> save(@RequestParam(value="memberId") String memberId,@RequestParam(value="bankId") String bankId,@RequestParam(value="amount") Double amount)
    {
        Integer code = tradeService.save(memberId,bankId,amount);
        String msg = "";
        switch (code){
            case 200:
                msg = "申请已提交";
                break;
            default:
                msg = "发生其它异常";
                break;
        }
        return  ServerResponse.createBySuccess(code,msg);
    }
}
